package com.ruoyi.web.controller.consumables;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.consumables.domain.ReceiveRecord;
import com.ruoyi.consumables.service.IReceiveRecordService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 领用记录Controller
 * 
 * @author ruoyi
 * @date 2023-04-22
 */
@Controller
@RequestMapping("/consumables/receiveRecord")
public class ReceiveRecordController extends BaseController
{
    private String prefix = "consumables/receiveRecord";

    @Autowired
    private IReceiveRecordService receiveRecordService;

    @RequiresPermissions("consumables:receiveRecord:view")
    @GetMapping()
    public String receiveRecord()
    {
        return prefix + "/receiveRecord";
    }

    /**
     * 查询领用记录列表
     */
    @RequiresPermissions("consumables:receiveRecord:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ReceiveRecord receiveRecord)
    {
        startPage();
        List<ReceiveRecord> list = receiveRecordService.selectReceiveRecordList(receiveRecord);
        return getDataTable(list);
    }

    /**
     * 导出领用记录列表
     */
    @RequiresPermissions("consumables:receiveRecord:export")
    @Log(title = "领用记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ReceiveRecord receiveRecord)
    {
        List<ReceiveRecord> list = receiveRecordService.selectReceiveRecordList(receiveRecord);
        ExcelUtil<ReceiveRecord> util = new ExcelUtil<ReceiveRecord>(ReceiveRecord.class);
        return util.exportExcel(list, "领用记录数据");
    }

    /**
     * 新增领用记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存领用记录
     */
    @RequiresPermissions("consumables:receiveRecord:add")
    @Log(title = "领用记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ReceiveRecord receiveRecord)
    {
        return toAjax(receiveRecordService.insertReceiveRecord(receiveRecord));
    }

    /**
     * 修改领用记录
     */
    @RequiresPermissions("consumables:receiveRecord:edit")
    @GetMapping("/edit/{receiveId}")
    public String edit(@PathVariable("receiveId") Long receiveId, ModelMap mmap)
    {
        ReceiveRecord receiveRecord = receiveRecordService.selectReceiveRecordByReceiveId(receiveId);
        mmap.put("receiveRecord", receiveRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存领用记录
     */
    @RequiresPermissions("consumables:receiveRecord:edit")
    @Log(title = "领用记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ReceiveRecord receiveRecord)
    {
        return toAjax(receiveRecordService.updateReceiveRecord(receiveRecord));
    }

    /**
     * 删除领用记录
     */
    @RequiresPermissions("consumables:receiveRecord:remove")
    @Log(title = "领用记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(receiveRecordService.deleteReceiveRecordByReceiveIds(ids));
    }
}
